package viewcomponents;

import java.awt.event.ActionEvent;
import java.io.IOException;

import javax.swing.AbstractAction;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;

import controller.Controller;

import view.SLogoView;

/**
 * Control all menu components in SLogoView
 *
 */
public class SLogoMenu 
{
	private JMenuBar myMenuBar;
	private SLogoTabManager myTabManager;
	private Controller myController;

	public SLogoMenu(Controller controller)
	{
		this(controller, new SLogoTabManager("SLogo", controller));
	}
	
	public SLogoMenu(Controller controller, SLogoTabManager tabManager)
	{
		myController = controller;
		myMenuBar = this.createMenu();
		myTabManager = tabManager;
	}
	
	/**
	 * 
	 * @return selected menu bar
	 */
	public JMenuBar getMenuBar()
	{
		return myMenuBar;
	}
	
	/**
	 * pass in the 
	 * @param manager
	 */
	public void setTab(SLogoTabManager manager)
	{
		myTabManager = manager;
	}
	
	/**
	 * create menu
	 * @return
	 */
	private JMenuBar createMenu()
	{
		JMenuBar menuBar;
        JMenu menu;

        //Create the menu bar.
        menuBar = new JMenuBar();

        //Build the first menu.
        menu = new JMenu("File");
        menuBar.add(menu);

//      a group of JMenuItems
//        menu.add(new AbstractAction("New")
//        {
//        	@Override
//        	public void actionPerformed (ActionEvent e) {
//        		try {
//					new SLogoView();
//				} catch (IOException e1) {
//					// TODO Auto-generated catch block
//					e1.printStackTrace();
//				}
//        	}
//        });
        
        menu.add(new AbstractAction("New")
        {
			@Override
			public void actionPerformed(ActionEvent e) {
				myTabManager.addTab("New Tab",myController);
			}
        });
        
        JMenuItem save = new JMenuItem("Save");
        menu.add(save);
        
        //a group of JMenuItems
        
        menu.add(new AbstractAction("Quit")
        {
            public void actionPerformed (ActionEvent e)
            {
                System.exit(0); // end program
            }
        });
		
        return menuBar;
	}
	
	
}
